﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MapInfo_MemberList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCadre();
            BindSoldiers();
            BindSoldiers2();
            
        }
        
            
    }
    public string GetDepartmentName(object obj)
    {
        if (obj == null)
            return "";
        Yipusoft.Account.Model.DepartmentInfo info = Yipusoft.Account.BLL.Department.GetDepartment(obj.ToString());
        if (info == null)
            return "";
        return info.FullName;
    }

    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        GvwCadre.PageIndex = PageIndex;
        BindCadre();
    }
    public void ListPageContral1_PageSizeChange2(int pageSize, int PageIndex)
    {

        this.gvSoldiers.PageIndex = PageIndex;
        BindSoldiers();
    }
    public void ListPageContral1_PageSizeChange3(int pageSize, int PageIndex)
    {


        this.gvwSoldier2.PageIndex = PageIndex;
        BindSoldiers2();
    }
    private string GetParameters()
    { 
        string DepartmentID=string.Empty;
        if (Request["DepartmentID"] == null)
            return string.Empty;
        if (!Request["DepartmentID"].Substring(0, 2).Equals("13"))
            DepartmentID = "13" + Request["DepartmentID"];
        else
            DepartmentID = Request["DepartmentID"];


        return DepartmentID;

    }
    private void BindCadre()
    {
        if (GetParameters() == string.Empty)
            return;

        List<Yipusoft.MapInfo.Model.SoldierArchiveInfo> list= new Yipusoft.MapInfo.BLL.Cadre().GetSoldiersByWhere(" DepartmentID=" + GetParameters());
        this.GvwCadre.DataSource = list;
        this.ListPageContral1.ItemCount = list.Count;
        this.GvwCadre.DataBind();
      
    }
    private void BindSoldiers()
    {
        if (GetParameters() == string.Empty)
            return;
        string Where = " DepartmentID='" + GetParameters() + "' And IsDelete=0  And IsContract=0";
        int Count= new Yipusoft.SoldierArchives.BLL.Soldier().GetSoldiersCountByWhere(Where);
        List<Yipusoft.SoldierArchives.Model.SoldierArchiveInfo> list = new Yipusoft.SoldierArchives.BLL.Soldier().GetSoldiersByWhere(Where, "SoldierID", " Desc", Count, 0);
        this.gvSoldiers.DataSource = list;
        this.ListPageContral2.ItemCount = list.Count;
        this.gvSoldiers.DataBind();

    }
    private void BindSoldiers2()
    {
        if (GetParameters() == string.Empty)
            return;
        string Where = " DepartmentID='" + GetParameters() + "' And IsDelete=0  And IsContract<>0";
        int Count = new Yipusoft.SoldierArchives.BLL.Soldier().GetSoldiersCountByWhere(Where);
        List<Yipusoft.SoldierArchives.Model.SoldierArchiveInfo> list = new Yipusoft.SoldierArchives.BLL.Soldier().GetSoldiersByWhere(Where, "SoldierID", " Desc", Count, 0);
        this.gvwSoldier2.DataSource = list;
        this.ListPageContral3.ItemCount = list.Count;
        this.gvwSoldier2.DataBind();

    }

    protected void GvwCadre_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (GvwCadre.PageIndex * GvwCadre.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    protected void gvSoldiers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (gvSoldiers.PageIndex * gvSoldiers.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    protected void gvSoldiers_RowDataBound2(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (gvwSoldier2.PageIndex * gvwSoldier2.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    protected void BtnID_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        new Yipusoft.MapInfo.BLL.Cadre().Delete(e.CommandArgument.ToString());
        BindCadre();
    }
}
